M = {}
local cmp = require('cmp')
local luasnip = require('luasnip')

M.setup = function()
  cmp.setup {
  	snippet = {
  		expand = function(args)
        luasnip.lsp_expand(args.body)
  		end
  	  },
      mapping = require('my.keymap').cmp_mapping(cmp),
      -- You should specify your *installed* sources.
      sources = {
  		  { name = 'nvim_lsp' },
  		  -- nvim lua API
  		  { name = 'nvim_lua' },
        -- luasnip
  		  { name = 'luasnip' },
  		  -- file path
  		  {name = 'path'},
  		  -- text
      	{ name = 'buffer' },
      },
      formatting = {
        format = function(entry, vim_item)
          -- set a name for each source
          vim_item.menu = ({
            nvim_lsp = "[LSP]",
            nvim_lua = "[Lua]",
            luasnip = "[LuaSnip]",
            path = "[Path]",
            buffer = "[Buffer]",
          })[entry.source.name]
          return vim_item
        end,
      },
  }
end

return M
